﻿using System;
using System.Reflection;
using Common.Model;
using Common.Orm;
using Common.Service;

namespace Common.Factory
{

    public class Factory<T>
    {
        private const string AssemblyPath = "Common.Service";
        private Factory()
        {

        }
        private static object CreateObject(string classNamespace)
        {
            object objType = DataCache.GetCache(classNamespace);
            if (objType == null)
            {
                try
                {
                    objType = Assembly.Load("school").CreateInstance(classNamespace);
                    DataCache.SetCache(classNamespace, objType);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
            return objType;
        }
        public static IRepository<T> Repository()
        {
            string classNamespace = AssemblyPath + "." + typeof(T).Name + "Service";
            object objType = CreateObject(classNamespace);
            return (IRepository<T>)objType;
        }
    }

    public class Factory
    {
        private const string AssemblyPath = "Common.Service";
        private Factory()
        {

        }
        private static object CreateObject(string classNamespace)
        {
            object objType = DataCache.GetCache(classNamespace);
            if (objType == null)
            {
                try
                {
                    objType = Assembly.Load("school").CreateInstance(classNamespace);
                    DataCache.SetCache(classNamespace, objType);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
            return objType;
        }
        public static Cd_UserService UserService()
        {
            string classNamespace = AssemblyPath + "." + "Cd_UserService";
            object objType = CreateObject(classNamespace);
            return (Cd_UserService)objType;
        }

    }

}